import urllib.request
import urllib.parse

# 翻译接口
url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
data = {
    'from': 'en',
    'to': 'zh',
    'query': 'hello',
    'transtype': 'realtime',
    'simple_means_flag': '3',
    'sign': '54706.276099',
    'token': '16a4442bf0b717b0c7301dc3c8c73216',
    'domain': 'common',
    'ts': '1705414404263'
}
data = urllib.parse.urlencode(data).encode('utf-8')

headers = {
    'Cookie': 'BIDUPSID=BB6A7CFAA2B6C1B9B055B1C739B9354B; PSTM=1701695982; BAIDUID=BB6A7CFAA2B6C1B9B055B1C739B9354B:SL=0:NR=10:FG=1; BDUSS=pMZUJvYWtXWlFiU00zbkNNUTBJRFgtd2gwbGZEUmhyQkNUZGJnZEJrQjRaNjlsRVFBQUFBJCQAAAAAAAAAAAEAAACdr10IsNfSu7uka2xvcwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHjah2V42odlaU; BDUSS_BFESS=pMZUJvYWtXWlFiU00zbkNNUTBJRFgtd2gwbGZEUmhyQkNUZGJnZEJrQjRaNjlsRVFBQUFBJCQAAAAAAAAAAAEAAACdr10IsNfSu7uka2xvcwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHjah2V42odlaU; BAIDUID_BFESS=BB6A7CFAA2B6C1B9B055B1C739B9354B:SL=0:NR=10:FG=1; ZFY=lSodykEAjFE6Hq50ULXZCdXwZ7MuW5otZlu4lMrPIuI:C; H_PS_PSSID=39999_40041_39824_40077_40134; RT="z=1&dm=baidu.com&si=34e3997e-3259-422f-bd68-fa9c8156c2b3&ss=lrez63uh&sl=8&tt=60h&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=43rx&ul=fn26&hd=fn30"; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1705414377; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1705414377; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; ab_sr=1.0.1_OTE1NDZmMTUyYWY2ZjMyM2Q2YTY5ZWZjZThmYzRiMDA3ZWVlOTBkZmRkZTljMGRiMmVmZTA4MGY2MjZhMWNiOWZhNWM0MjJkYThmYmFjMDg4YjMxMjE5OWYzZjE0ZDJlOTk3MGJlNDQ1OTBjZTIzOTBiNGE2YWI4MzkxNTg2YzlhYTI5MGYxYjlhYjg3MjlmODUxMTc5ODQ1YmE5NmUzY2ZjZmVhOWE5ZmI1MzFiNzg3MGE1ZGZhNGMzOWZmZTY1NjA2ODA0NDFjNmUxZmNkOWZhMTlmMWZhNjcyMjVmZmE='
}

request = urllib.request.Request(url=url, data=data, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf-8')

print(content)

import json

json_obj = json.loads(content)

print(json_obj)